******************************************
* KNOWING DEMOCRACY MAKES PEOPLE LOVE IT *
******************************************

* CONTENT:
// 1. Organizing and cleaning up variables
// 2. Analysis

set more off

use main_survey.dta, clear


* ORGANIZING AND CLEANING UP VARIABLES
**************************************

* A. Dependent variables
*************************

* Democratic preference #1: Democracy v. Authoritarianism

gen pref_01=1 if q0011==1
replace pref_01=2 if q0011==3
replace pref_01=3 if q0011==2
replace pref_01=-1 if q0011==4 | q0011==5
replace pref_01=. if q0011==.
lab define PREF_01 1 "Under some circumstances, an authoritarian regime can be preferable to a democratic one" 2 "For people like me, it doesn’t matter if we have a democratic or a nondemocratic government" 3 "Democracy is always preferable to any other kind of government" -1 "DK", modify
lab val pref_01 PREF_01

* Democratic preference #2: Importance of living in a democracy

encode q0012, gen(q0012_n)

gen pref_02=q0012_n
replace pref_02=. if q0012_n==1
replace pref_02=1 if q0012_n==3 | q0012_n==2
replace pref_02=2 if q0012_n==5
replace pref_02=3 if q0012_n==6
replace pref_02=4 if q0012_n==7
replace pref_02=5 if q0012_n==8
replace pref_02=6 if q0012_n==9
replace pref_02=7 if q0012_n==10
replace pref_02=8 if q0012_n==11
replace pref_02=9 if q0012_n==12
replace pref_02=10 if q0012_n==4
lab define PREF_02 1 "Not at all important" 10 "Very important" -1 "DK"
lab val pref_02 PREF_02

* Democratic preference #3: Satisfaction with democracy

encode q0013, gen(q0013_n)

gen pref_03=q0013_n
replace pref_03=. if q0013_n==1
replace pref_03=1 if q0013_n==2
replace pref_03=2 if q0013_n==4
replace pref_03=3 if q0013_n==5
replace pref_03=4 if q0013_n==6
replace pref_03=5 if q0013_n==7
replace pref_03=6 if q0013_n==8
replace pref_03=7 if q0013_n==9
replace pref_03=8 if q0013_n==10
replace pref_03=9 if q0013_n==11
replace pref_03=10 if q0013_n==3
lab define PREF_03 1 "Not at all satisfied" 10 "Very satisfied" -1 "DK"
lab val pref_03 PREF_03

* B. Manipulation check variables
*********************************

* Recoding open-ended definition into variables

encode q0014_0001, gen(q0014_0001_n)

recode q0014_0001_n (1=.) (1 13 14 16 18 27 28 32 34 40 41 43 44 49 51 235 236 237 239/245 248 259 265 279/282 286/292 294/326 333 365/369 371 372 379 380 381 386 387 389 391/394 397 399/401 408/410 413 418 419 426 427 429 430 433 436 438 441 444 445 446 450/454 457 459 461 462 464/470 480 481 540/545 549 555 805/808 812/838 841 844/862 867 878/880 887 888 890/892 894 896 903/905 907/910 912 914/933 936 940 943 944/954 966 969/972 979/981 991 992 994 996 998 1003/1006 1008/1017 1019 1020 1025 1035/1037 1043/1047 1050 1052/1055 1057/1098 1100/1115 1118 1125 1128 1137/1143 1146/1148 1153 1156 1159 1162/1169 1170/1180 1182 1183 1186 1197 1198 1201 1203/1207 1209 1213/1215 1222/1224 1231 1232 1240 1246 1249 1252/1258 1260 1261 1263/1268 1270 1272 1276/1291 1296 1299 1302/1310 1312/1314 1319 1348 1350 1365/1370 1371/1376 1380 1382/1384 1393 1394 1425 1426 1432/1440 1442 1443 1449 1450 1452 1454 1455 1459/1464 1467 1506/1508 1515 1527/1529 1534/1537 1540 1541 1543 1544 1550 1552/1557 1560 1563/1568 1570/1574 1577 1578 1586 1589 383 941 1029 = 1 "Procedural") (15 17 19 22/26 46 47 50 54/234 238 246 258 262 275 284 285 338 340/364 367 370 373 374 377 378 382 395 396 398 402/405 407 412 414 415 420/424 431 434 437 439 448 456 458 471 472 477 478 479 486/490 501/525 529 530 537 554 557 570/804 811 843 870/874 881 882 893 902 906 934 935 939 955 957/965 967 968 973 975 976 978 982/988 993 995 1021/1024 1033 1041 1042 1048 1051 1099 1122 1123 1131/1134 1154 1157 1158 1160 1161 1170 1187/1192 1199 1200 1202 1211 1212 1216/1221 1225/1229 1233/1235 1237 1239 1241/1245 1250 1259 1262 1271 1273 1276 1292/1295 1297 1298 1301 1311 1324 1325 1329 1330 1331 1336 1338 1339 1347 1355 1377/1379 1390/1392 1397 1399/1421 1424 1427 1446/1448 1456 1457 1458 1465 1466 1468/1476 1480/1504 1509 1510 1512 1513 1520/1525 1546/1548 1551 1558 1559 1561 1562 1590 249 1152 1396 = 2 "Freedom/equality") (20 21 25 42 45 247 250/254 256 260 261 263 266/269 273 276 283 339 375 376 406 417 425 428 432 475 476 499 526 528 531 535 547 550 552 553 558/561 563/567 810 840 842 863 864 865 868 869 875/877 883 899 911 937 938 944 956 974 977 989 999/1001 1126 1127 1129 1130 1136 1155 1275 1323 1327 1328 1332 1333 1358/1361 1423 1429 1430 1478 1505 1511 1518 1519 1526 1539 1545 1549 1576 1580 1587 277 1181 = 3 "Outcomes") (3 52 53 255 257 264 270/272 328 335/337 388 390 416 440 449 455 463 483 485 491 495 500 527 532 536 546 548 551 569 886 900 901 942 990 1026 1056 1117 1119/1121 1144 1145 1194/1196 1230 1274 1300 1326 1346 1352 1357 1362 1363 1371 1386 1395 1398 1422 1428 1445 1477 1517 1538 442 = 4 "Nonsubstantive") (9 30 31 33 35/37 48 274 278 293 329/332 334 384 385 411 435 443 447 460 473 474 482 493 494 538 539 556 562 568 809 839 866 885 889 895 913 997 1002 1007 1028 1030/1032 1039 1040 1049 1116 1124 1135 1149 1184 1185 1193 1210 1236 1238 1247 1248 1251 1269 1316 1317 1351 1372 1385 1387 1431 1444 1451 1453 1479 1514 1531 1533 1584 1588 1591 = 5 "Negative") (484 492 496/498 897 1027 1208 1322 1337 1349 1353 1354 1579 1585 = -1 "DK") (6 10/12 29 38 39 327 533 534 884 898 1018 1034 1038 1150 1151 1315 1318 1320 1321 1334 1335 1340/1345 1356 1364 1381 1388 1389 1441 1516 1530 1532 1542 1569 1575 1581/1583 7 8 = -2 "PNA"), gen(def_01)

* Creating a procedural v. rest variable

recode def_01 (-2=0 "Missing") (-1=0 "Missing") (.=0 "Missing") (1=1 "Procedural") (2=2 "Freedom Equality") (3=3 "Outcomes") (4/5=4 "Not meaningful"), gen(mod)

* C. Treatment
**************

gen treatment=.
replace treatment=0 if q0011_question==1
replace treatment=1 if q0011_question==2
replace treatment=. if q0011_question==.

lab define TREATMENT 1 "Treatment" 0 "Control", modify
lab val treatment TREATMENT

* D. Covariates
****************

* Gender

gen gender=1 if q0003==1
replace gender=0 if q0003==2
replace gender=. if q0003>2
lab define GENDER 1 "Female" 0 "Male"
lab val gender GENDER

* Age group

gen agegroup=q0004
replace agegroup=6 if q0004==7
replace agegroup=. if q0004==. | q0004>7
lab define AGEGROUP 1 "17-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+"
lab val agegroup AGEGROUP

gen age=agegroup
replace age=5 if agegroup==6
replace age=. if agegroup==.
lab define AGE 1 "17-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55+", modify
lab val age AGE

* Education

gen raw_edu=.
replace raw_edu=1 if q0005_0001==1
replace raw_edu=2 if q0005_0002==1 | q0005_0003==1
replace raw_edu=3 if q0005_0004==1 | q0005_0005==1
replace raw_edu=4 if q0005_0006==1 | q0005_0007==1
replace raw_edu=5 if q0005_0008==1 | q0005_0009==1
replace raw_edu=. if q0005_0010==1 | q0005_0011==1
lab define RAW_EDU 1 "None" 2 "Primary" 3 "Jun. secondary" 4 "Sen. secondary" 5 "University", modify
lab val raw_edu RAW_EDU

gen education=.
replace education=1 if q0005_0001==1 | q0005_0002==1 | q0005_0003==1 | q0005_0004==1 | q0005_0005==1
replace education=2 if q0005_0006==1 | q0005_0007==1
replace education=3 if q0005_0008==1 | q0005_0009==1
replace education=. if q0005_0010==1 | q0005_0011==1
lab define EDUCATION 1 "Low" 2 "Medium" 3 "High", modify
lab val education EDUCATION

* Income

gen income=q0006
replace income=. if q0006==. | q0006>=6
lab define INCOME 1 "< IDR 1,500,000" 2 "IDR 1,500,001 - 3,000,000" 3 "IDR 3,000,001 - 4,500,000" 4 "4,500,001 - 6,000,000" 5 "6,000,001 >" 
lab val income INCOME

* City of residence

encode q0007, gen(q0007_n)
recode q0007_n (1=.) (6 9 11 12 13 14 15 89 102 105 109 110 111 112 113 114 115 116 122 123 124 128 129 130 141 142 143 144 145 146 147 148 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 188 189 190 228 315 333 402 408 437 438 441 443 444 445 450 451 452 453 454 455 456 457 458 480 = 1 "Jakarta") (23 24 35 50 51 52 53 54 55 56 57 68 104 132 196 199 203 207 208 214 233 239 428 429 432 439 440 465 = 2 "Bandung") (8 36 38 58 59 64 338 340 345 355 356 367 380 381 382 383 384 386 487 = 3 "Surabaya") (2 17 18 39 69 70 71 72 73 74 80 94 96 97 98 197 198 198 200 204 205 209 215 240 311 389 426 433 460= 4 "Bekasi") (271 286 287 288 289 290 291 292 293 434 470 471 472 473 474 = 5 "Medan") (7 10 16 19 20 21 22 25 26 27 31 32 33 34 37 40 41 42 43 44 45 46 47 48 49 60 61 62 63 65 66 67 75 76 77 78 79 81 82 83 84 85 86 87 90 91 92 93 95 99 100 101 106 107 108 118 119 120 121 136 137 140 149 176 177 178 179 180 181 182 183 184 186 191 192 193 194 195 201 202 206 210 211 212 213 216 217 218 219 220 221 222 223 224 225 226 227 229 230 231 232 236 237 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 267 268 269 270 272 273 274 275 276 277 278 279 280 281 282 283 284 285 294 295296 297 299 300 302 303 304 305 306 307 308 309 310 312 313 314 316 317 318 319 320 321 323 324 325 326 327 328 329 330 331 332 334 335 336 341 342 343 344 347 348 349 350 351 352 353 354 357 358 359 360 361 362 364 365 366 368 369 370 371 372 373 374 375 376 377 378 379 385 387 388 390 391 392 393 394 395 396 397 398 399 400 401 403 404 405 406 407 409 410 411 412 413 414 415 416 420 422 423 427 430 431 435 436 442 446 459 462 464 466 467 468 475 476 477 478 479 481 482 483 484 486 489 491 493 494 103 185 295 296 298 339 485 488 490 = 99 "Others") (else=.), gen(city) // Non-target cities will be listed as others. Postcode entries will be translated into closest city.

gen city_clean=city if city<6


* Weight

gen w1_c=.
replace w1_c=50.26/51.55 if gender==0 & city==1
replace w1_c=51.50/50.71 if gender==0 & city==2
replace w1_c=49.40/49.46 if gender==0 & city==3
replace w1_c=50.96/49.16 if gender==0 & city==4
replace w1_c=49.39/55.56 if gender==0 & city==5
replace w1_c=49.74/48.45 if gender==1 & city==1
replace w1_c=48.50/49.29 if gender==1 & city==2
replace w1_c=50.60/50.54 if gender==1 & city==3
replace w1_c=49.04/50.84 if gender==1 & city==4
replace w1_c=50.61/44.44 if gender==1 & city==5

gen w2_c=.
replace w2_c=20.79/48.25 if age==1 & city==1
replace w2_c=27.37/32.45 if age==2 & city==1
replace w2_c=22.29/10.48 if age==3 & city==1
replace w2_c=15.58/5.99 if age==4 & city==1
replace w2_c=13.97/2.83 if age==5 & city==1
replace w2_c=25.39/55.05 if age==1 & city==2
replace w2_c=23.05/27.62 if age==2 & city==2
replace w2_c=19.84/9.57 if age==3 & city==2
replace w2_c=15.70/4.87 if age==4 & city==2
replace w2_c=16.02/2.89 if age==5 & city==2
replace w2_c=22.89/48.91 if age==1 & city==3
replace w2_c=23.17/26.64 if age==2 & city==3
replace w2_c=19.98/13.50 if age==3 & city==3
replace w2_c=16.57/6.57 if age==4 & city==3
replace w2_c=17.39/4.37 if age==5 & city==3
replace w2_c=25.44/53.56 if age==1 & city==4
replace w2_c=28.19/28.21 if age==2 & city==4
replace w2_c=22.13/12.54 if age==3 & city==4
replace w2_c=14.67/3.70 if age==4 & city==4
replace w2_c=9.57/1.99 if age==5 & city==4
replace w2_c=29.17/61.46 if age==1 & city==5
replace w2_c=23.65/29.11 if age==2 & city==5
replace w2_c=19.40/6.47 if age==3 & city==5
replace w2_c=14.41/2.70 if age==4 & city==5
replace w2_c=13.36/0.27 if age==5 & city==5

gen w3_c=.
replace w3_c=48.02/4.81 if education==1 & city==1
replace w3_c=36.99/42.48 if education==2 & city==1
replace w3_c=14.99/52.70 if education==3 & city==1
replace w3_c=49.54/2.77 if education==1 & city==2
replace w3_c=35.59/41.88 if education==2 & city==2
replace w3_c=14.88/55.35 if education==3 & city==2
replace w3_c=53.32/4.04 if education==1 & city==3
replace w3_c=33.11/38.24 if education==2 & city==3
replace w3_c=13.56/57.72 if education==3 & city==3
replace w3_c=29.32/1.74 if education==1 & city==4
replace w3_c=45.58/52.91 if education==2 & city==4
replace w3_c=25.09/45.35 if education==3 & city==4
replace w3_c=55.25/1.88 if education==1 & city==5
replace w3_c=35.48/34.32 if education==2 & city==5
replace w3_c=9.27/63.81 if education==3 & city==5

gen weight=w1_c*w2_c*w3_c


* E. Label variables
********************

lab var gender "Gender"
lab var agegroup "Age-raw data"
lab var age "Age"
lab var raw_edu "Education-raw data"
lab var education "Education"
lab var income "Income"
lab var city "City of residence"
lab var pref_01 "Democracy v. authoritarianism"
lab var pref_02 "Importance of democracy"
lab var pref_03 "Satisfaction w/ democracy"
lab var treatment "Treatment"
lab var mod "Meaning of democracy"

* ANALYSIS
***********

* A. Sample representativeness
******************************

* Gender

tab city gender if city<6, row

* Education

tab city raw_edu if city<6, row

* Agegroup

tab city agegroup if city<6, row

* B. Balance test
*****************

logit treatment gender age education income i.city if city<=6
margins, dydx(*) post
outreg2 using balance.doc, se dec(2) alpha(0.001, 0.01, 0.05) replace label

logit treatment gender age income i.city if city<=6 & education==1
margins, dydx(*) post
outreg2 using balance.doc, se dec(2) alpha(0.001, 0.01, 0.05) append label

logit treatment gender age income i.city if city<=6 & education==2
margins, dydx(*) post
outreg2 using balance.doc, se dec(2) alpha(0.001, 0.01, 0.05) append label

logit treatment gender age income i.city if city<=6 & education==3
margins, dydx(*) post
outreg2 using balance.doc, se dec(2) alpha(0.001, 0.01, 0.05) append label



* C. Manipulation check
***********************

tab mod treatment if city<6, col chi2
bysort education: tab mod treatment if city<6, col chi2

* D. Descriptives of dependent variable
***************************************

gen pref_01_01=0 if pref_01==-1
replace pref_01_01=1 if pref_01>0
replace pref_01_01=. if pref_01==.
lab define PREF_01_01 0 "DK" 1 "Substantive", modify
lab val pref_01_01 PREF_01_01

gen pref_01_02=1 if pref_01==3 | pref_01==1
replace pref_01_02=0 if pref_01==2
replace pref_01_02=. if pref_01==. | pref_01==-1
lab define PREF_01_02 0 "Absense of self efficacy" 1 "Presence of self efficacy", modify
lab val pref_01_02 PREF_01_02

gen pref_01_03=1 if pref_01==3 
replace pref_01_03=0 if pref_01==1
replace pref_01_03=. if pref_01==. | pref_01==-1 | pref_01==2
lab define PREF_01_03 0 "Democracy is not always preferable" 1 "Democracy is always preferable", modify
lab val pref_01_03 PREF_01_03

tab1 pref_01_01 pref_01_02 pref_01_03 if city<6
sum pref_02 pref_03 if city<6

* E. Treatment effects
**********************

* Preference 1: DK v. the rest

qui logit pref_01_01 treatment if city<6
margins, dydx(*) post
outreg2 using reg.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No)  ctitle("Provide an answer") replace label

qui logit pref_01_01 treatment gender education age income i.city if city<6
margins, dydx(*) post
outreg2 using reg.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide an answer") append label

qui logit pref_01_01 treatment if city<6 [iw=weight]
margins, dydx(*) post
outreg2 using reg.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) ctitle("Provide an answer (weighted)")  append label

qui logit pref_01_01 treatment gender education age income i.city if city<6 [iw=weight]
margins, dydx(*) post
outreg2 using reg.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide an answer (weighted)") append label

* Preference 1: absense of self efficacy v. self efficacy (without DK)

qui logit pref_01_02 treatment if city<6
qui margins, dydx(*) post
outreg2 using reg2.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) ctitle("Provide a preference") replace label

qui logit pref_01_02 treatment gender education age income i.city if city<6
qui margins, dydx(*) post
outreg2 using reg2.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide a preference") append label


qui logit pref_01_02 treatment if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg2.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) ctitle("Provide a preference (weighted)") append label

qui logit pref_01_02 treatment gender education age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg2.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide a preference (weighted)") append label

* Preference 1: Pro v. Against democracy

qui logit pref_01_03 treatment if city<6
qui margins, dydx(*) post
outreg2 using reg3.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) ctitle("Prefer democracy")  replace label

qui logit pref_01_03 treatment gender education age income i.city if city<6
qui margins, dydx(*) post
outreg2 using reg3.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Prefer democracy")  append label


qui logit pref_01_03 treatment if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg3.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No)  ctitle("Prefer democracy (weighted)") append label

qui logit pref_01_03 treatment gender education age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg3.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Prefer democracy (weighted)")  append label

* Preference 2: Living in democracy

qui reg pref_02 treatment if city<6
outreg2 using reg4.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) ctitle("Living in democracy important") replace label

qui reg pref_02 treatment gender education age income i.city if city<6
outreg2 using reg4.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Living in democracy important") append label


qui reg pref_02 treatment if city<6 [iw=weight]
outreg2 using reg4.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) ctitle("Living in democracy important (weighted)") append label 

qui reg pref_02 treatment gender education age income i.city if city<6 [iw=weight]
outreg2 using reg4.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Living in democracy important (weighted)") append label

* Preference 3: SWD

qui reg pref_03 treatment if city<6
outreg2 using reg5.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) ctitle("Satisfaction with democracy") replace label

qui reg pref_03 treatment gender education age income i.city if city<6
outreg2 using reg5.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Satisfaction with democracy") append label

qui reg pref_03 treatment if city<6 [iw=weight]
outreg2 using reg5.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) ctitle("Satisfaction with democracy (weighted)") append label

qui reg pref_03 treatment gender education age income i.city if city<6 [iw=weight]
outreg2 using reg5.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Satisfaction with democracy (weighted)") append label


* F. Robustness test 
********************

* Multinomial logit regression

qui mlogit pref_01 treatment if city<6
outreg2 using reg6.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) replace label

qui mlogit pref_01 treatment gender education age income i.city if city<6
outreg2 using reg6.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, Yes, City FE, Yes) append label

qui mlogit pref_01 treatment if city<6 [iweight=weight]
outreg2 using reg7.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) replace label

qui mlogit pref_01 treatment gender education age income i.city if city<6 [iweight=weight]
outreg2 using reg7.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, Yes, City FE, Yes) append label

* G. Heterogenous effects
**************************

* Regression table

gen interaction=treatment*education
lab var interaction "Treatment x Education"

qui logit pref_01_01 interaction treatment education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg8.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide an answer") replace label

qui logit pref_01_02 interaction treatment education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg8.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide a preference") append label

qui logit pref_01_03 interaction treatment education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg8.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Prefer democracy") append label

qui reg pref_02 interaction treatment education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg8.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Living in democracy important") append label

qui reg pref_03 interaction treatment education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg8.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Satisfaction with democracy") append label

* Graphs

qui logit pref_01_02 i.treatment##c.education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(treatment) at(education=(1(1)3)) atmeans
marginsplot, title("Provide a preference") scheme(s2mono) ylab(-0.5(0.1)0.5) ytitle("Marginal effects of treatment") xtitle("Education") graphregion(color(white)) nolab recastci(rline) recast(line) ci(lp(dash)) 
graph save pref_0102_education.gph, replace

qui logit pref_01_03 i.treatment##c.education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(treatment) at(education=(1(1)3)) atmeans
marginsplot, title("Democracy always preferable") scheme(s2mono) ylab(-0.5(0.1)0.5) ytitle("") xtitle("Education") graphregion(color(white)) nolab recastci(rline) recast(line) ci(lp(dash)) 
graph save pref_0103_education.gph, replace

graph combine pref_0102_education.gph pref_0103_education.gph, row(1) title("") graphregion(color(white))
graph export heterogenous1.png, replace

qui reg pref_02 i.treatment##c.education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(treatment) at(education=(1(1)3)) atmeans
marginsplot, title("Living in democracy important") scheme(s2mono) ytitle("Marginal effects of treatment") xtitle("Education") graphregion(color(white)) nolab recastci(rline) recast(line) ci(lp(dash)) ylab(-2(1)2)
graph save heterogenous2.gph, replace

qui reg pref_03 i.treatment##c.education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(treatment) at(education=(1(1)3)) atmeans
marginsplot, title("Satisfaction with democracy") scheme(s2mono) ytitle("") xtitle("Education") graphregion(color(white)) nolab recastci(rline) recast(line) ci(lp(dash)) ylab(-2(1)2)
graph save heterogenous3.gph, replace

graph combine heterogenous2.gph heterogenous3.gph, row(1) title("") graphregion(color(white))
graph export heterogeneous2and3.png, replace

* Alternative coding of education

gen interaction_low=0
gen interaction_med=0

replace interaction_low=treatment if education==1
replace interaction_med=treatment if education==2

qui logit pref_01_01 interaction_low interaction_med i.treatment ib(3).education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg9.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide an answer") replace label

qui logit pref_01_02 interaction_low interaction_med  i.treatment ib(3).education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg9.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide a preference") append label

qui logit pref_01_03 interaction_low interaction_med  i.treatment ib(3).education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg9.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Support democracy") append label

qui reg pref_02 interaction_low interaction_med  i.treatment ib(3).education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg9.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Living in democracy important") append label

qui reg pref_03 interaction_low interaction_med i.treatment ib(3).education gender age income i.city if city<6 [iw=weight]
qui margins, dydx(*) post
outreg2 using reg9.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Satisfaction with democracy") append label

* H. Bootstrapped CIs
*********************

svyset RespondentID [iw=weight], strata(city_clean)
bsweights bw, reps(1000) n(1) seed(123)

svyset [iw=weight], bsrweight(bw*) vce(bootstrap)

save resample.dta, replace

* Preference 1.2: absense of self efficacy v. self efficacy (without DK)

svy bootstrap _b: logit pref_01_02 treatment if pref_01_02!=.
margins, dydx(*) post
outreg2 using reg_bs1.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) replace label

svy bootstrap _b: logit pref_01_02 treatment gender education age income i.city_clean if pref_01_02!=.
margins, dydx(*) post
outreg2 using reg_bs1.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Provide a preference") append label

* Preference 1.3: Pro v. Against democracy

svy bootstrap _b: logit pref_01_03 treatment if pref_01_03!=.
margins, dydx(*) post
outreg2 using reg_bs1.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) append label

svy bootstrap _b: logit pref_01_03 treatment gender education age income i.city_clean if pref_01_03!=.
margins, dydx(*) post
outreg2 using reg_bs1.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Prefer democracy")  append label

* Preference 2 and 3 (Pref 2: 'living in democracy' | Pref 3: 'SWD')

svy bootstrap _b: reg pref_02 treatment if pref_02!=.
outreg2 using reg_bs1.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) append label

svy bootstrap _b: reg pref_02 treatment gender education age income i.city_clean if pref_02!=.
outreg2 using reg_bs1.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Living in democracy important") append label

svy bootstrap _b: reg pref_03 treatment if pref_03!=.
outreg2 using reg_bs1.doc, se dec(2) alpha(0.001, 0.01, 0.05) addtext(Control, No, City FE, No) append label

svy bootstrap _b: reg pref_03 treatment gender education age income i.city_clean if pref_03!=.
outreg2 using reg_bs1.doc, se dec(2) alpha(0.001, 0.01, 0.05) drop(i.city) addtext(Control, Yes, City FE, Yes) ctitle("Satisfaction with democracy") append label

* In the text
*************

* External check for MOD coding

recode q0014_0001_n (1=.) (13 14 16 27 51 235 236 237 239/245 265 279/282 286/292 294/326 333 365/369 371 372 379 380 381 386 387 389 391/394 397 399/401 408/410 413 418 419 426 427 429 430 433 436 438 441 444 445 446 450/454 457 459 461 462 545 549 555 805/808 812/838 841 844/862 867 878/880 887 888 890/892 894 896 903/905 907/910 912 914/931 933 936 940 943 944/952 954 966 969/972 979/981 991 992 994 996 998 1004  1019 1020 1025 1035/1037 1043/1047 1050 1052/1055 1057/1085 1088/1098 1100/1105 1107 1108 1110/1115 1118 1125 1128 1137/1143 1146/1148 1153 1156 1159 1162/1169 1170/1180 1182 1183 1186 1197 1198 1201 1203 1205/1207 1209 1213/1215 1222/1224 1231 1232 1240 1246 1249 1252/1258 1260 1261 1263/1268 1270 1272 1276/1291 1296 1299 1302/1310 1312/1314 1319 1348 1350 1365/1370 1371/1376 1380 1382/1384 1393 1394 1425 1426 1432/1440 1442 1443 1449 1450 1452 1454 1455 1459 1463 1464 1467 1506 1507 1515 1534/1537 1540 1541 1543 1544 1550 1552/1557 1560 1563/1568 1570/1574 1577 1578 1586 1589 383 941 1029 28 32 34 40 41 43 44 49 468 480 481 541 542 544 = 1 "Procedural") (15 17 46 47 50 54/234 238 246 262 275 284 285 338 340/355 472 477 478 479 486/490 501/525 537 554 557 570 571 572 583/804 811 843 870/874 881 882 893 902 906 934 935 939 955 957/965 967 968 973 975 976 982/988 993 995 1021/1023 1033 1042 1048 1051 1122 1123 1131/1134 1154 1157 1158 1160 1161 1170 1187/1192 1199 1200 1202 1211 1212 1216/1221 1225/1229 1233/1235 1237 1239 1241/1245 1250 1259 1271 1273 1276 1292/1295 1297 1298 1301 1311 1324 1325 1330 1331 1336 1338 1339 1347 1355 1377/1379 1390 1397 1399/1421 1424 1427 1446/1448 1456 1457 1458 1465 1466 1468/1475 1481/1504 1509 1510 1512 1513 1520/1525 1546/1548 1551 1558 1559 1561 1562 1590 249 1152 357/364 367 370 373 374 377 378 382 395 396 398 402/405 407 412 414 415 420 422/424 434 437 439 448 458 471 1396 = 2 "Freedom/equality") (19/26 42 45 247 250/254 256 261 263 266/269 273 276 283 339 375 376 406 417 425 428 432 475 476 499 526 528 531 535 547 550 552 553 558/561 563/567 810 840 842 863 864 865 868 869 875/877 883 899 911 937 938 944 956 974 977 989 999/1001 1126 1127 1129 1130 1136 1155 1275 1323 1327 1328 1332 1333 1358/1361 1423 1429 1430 1478 1505 1511 1518 1519 1526 1539 1545 1549 1576 1580 1587 277 1181 258 356 421 431 456 529 530 540 543 573/582 932 978 1003 1016 1024 1041 1086 1087 1099 1109 1262 1329 1391 1392 1476 1480 = 3 "Outcomes")(484 492 496/498 897 1027 1208 1322 1337 1349 1353 1354 1579 1585 6 10/12 29 38 39 327 533 534 884 898 1018 1034 1038 1150 1151 1315 1318 1320 1321 1334 1335 1340/1345 1356 1364 1381 1388 1389 1441 1516 1530 1532 1542 1569 1575 1581/1583 7 8 4 5= -1 "DK") (3 18 52 53 255 257 259 260 264 270/272 328 335/337 388 390 416 440 449 455 463 483 485 491 495 500 527 532 536 546 548 551 953 1005 1006 1008/1015 1017 1106 1144 1145 1194/1196 1230 1274 1300 1326 1346 1352 1357 1362 1363 1371 1386 1395 1398 1422 1428 1445 1477 1517 1538 442 9 30 31 33 35/37 48 274 278 293 329/332 334 384 385 411 435 443 447 460 473 474 482 493 494 538 539 885 889 895 913 997 1002 1007 1028 1030/1032 1039 1040 1049 1116 1124 1135 1149 1184 1185 1193 1204 1210 1236 1238 1247 1248 1251 1269 1316 1317 1351 1372 1385 1387 1431 1444 1451 1453 1479 1508 1514 1527 1528 1529 1531 1533 1584 1588 1591 569 886 900 901 942 990 1026 1056 1117 1119/1121 556 562 568 809 839 866 248 464/467 469 470 1460 1461 1462 = 0 "Not meaningful") , gen(mod_check)

recode mod_check (-1=.), gen(mod_check_clean)
label val mod_check_clean mod

corr mod mod_check_clean // 93.67

kap mod mod_check_clean
